package top.codecrab.cloudalibaba.controller;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import top.codecrab.cloudalibaba.service.AccountService;
import top.codecrab.springcloud.entity.response.Result;

import javax.annotation.Resource;
import java.math.BigDecimal;

@RestController
@RequestMapping("/account")
public class AccountController {

    @Resource
    private AccountService accountService;

    /**
     * 扣减账户余额
     */
    @PostMapping("/decrease")
    public Result decrease(@RequestParam("userId") Long userId, @RequestParam("money") BigDecimal money, @RequestParam("success") boolean success) {
        accountService.decrease(userId, money);
        if (!success) {
            int a = 1 / 0;
        }
        return new Result(200, "扣减账户余额成功！");
    }
}


